package com.heyige.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("quota_packages")
public class QuotaPackage {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    @TableField("name")
    private String name;
    
    @TableField("description")
    private String description;
    
    @TableField("quota")
    private Integer quota;
    
    @TableField("price")
    private Double price = 0.0;
    
    @TableField("discount_price")
    private Double discountPrice;
    
    @TableField("is_active")
    private Boolean isActive = true;
    
    @TableField("sort_order")
    private Integer sortOrder = 0;
    
    @TableField("sales_count")
    private Integer salesCount = 0;
    
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    
    /**
     * 获取实际价格（如果有折扣价则返回折扣价）
     */
    public Double getActualPrice() {
        return discountPrice != null ? discountPrice : price;
    }
    
    /**
     * 获取折扣百分比
     */
    public Double getDiscountPercentage() {
        if (discountPrice == null || price <= 0) {
            return 0.0;
        }
        return (1 - discountPrice / price) * 100;
    }
}